//
//  HMViewController.m
//  HMHorizontalGridView
//
//  Created by wy46817@gmail.com on 09/12/2017.
//  Copyright (c) 2017 wy46817@gmail.com. All rights reserved.
//

#import "HMViewController.h"
#import <HMHorizontalGridView/HMHorizontalGridView.h>
#import <Masonry/Masonry.h>
@interface HMViewController ()<HMHorizontalGridViewDelegate,HMHorizontalGridViewDataSource>

@property(strong ,nonatomic) HMHorizontalGridView *horizontalGridView;

@end

@implementation HMViewController{
    NSInteger _count;
}

- (void)viewDidLoad
{
    [super viewDidLoad];

    _count = arc4random_uniform(100);
    NSLog(@"%zd",_count);

    self.horizontalGridView = [HMHorizontalGridView new];

    [self.view addSubview:self.horizontalGridView];

    [self.horizontalGridView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self.view);
        make.width.equalTo(self.view);
        make.top.equalTo(self.view).offset(50);
        make.height.mas_equalTo(240);
    }];

    self.horizontalGridView.delegate = self;
    self.horizontalGridView.datasource = self;
    [self.horizontalGridView reloadData];

}

#pragma mark - HMHorizontalGridViewDataSource -
//数量
-(NSInteger)numberOfItemInHorizontalGridView:(HMHorizontalGridView *)horizontalGridView
{
    return _count;
}

//标题
- (NSString *)horizontalGridView:(HMHorizontalGridView *)horizontalGridView titleForItemAtIndex:(NSInteger)index{
    return [NSString stringWithFormat:@"%zd",index];
}

//图标url
- (NSURL *)horizontalGridView:(HMHorizontalGridView *)horizontalGridView urlForItemAtIndex:(NSInteger)index{
       return [NSURL URLWithString:@"http://img4.imgtn.bdimg.com/it/u=1439684490,613068850&fm=200&gp=0.jpg"];
}

#pragma mark - HMHorizontalGridViewDelegate -
- (NSInteger)numberOfRowsInHorizontalGridView:(HMHorizontalGridView *)horizontalGridView
{
    return 4;
}

-(NSInteger)numberOfColumnsInHorizontalGridView:(HMHorizontalGridView *)horizontalGridView{
    return 5;
}



@end
